use umas0009_output, clear

sort zipcode
merge zipcode using "zcta_cbsa_rel_10.dta"
drop if _m<3

gen region=1 if cbsa==14460
replace region=2 if cbsa==12700 | cbsa==39300
replace region=3 if cbsa==49340
replace region=4 if cbsa==38340 | cbsa==44140
label define region 1 "Boston Area" 2 "New Bedford/Cape Cod" 3 "Central MA" 4 "Western MA"
label values region region

gen region2=1 if region==1
replace region2=2 if region>1
label define region2 1 "Boston Area" 2 "Rest of MA"
label values region2 region2



gen leaner=q7a
recode leaner 2=1 1=2 3=.
gen senwleaners=q7
replace senwleaners=1 if leaner==1
replace senwleaners=2 if leaner==2
label define sen 1 "Gomez (Rep)" 2 "Markey (Dem)" 3 "someone else" 4 "not sure" 5 "would not vote"
label val senwleaners sen

gen incomecat=1 if faminc<=4
replace incomecat=2 if faminc>4 & faminc<10
replace incomecat=3 if faminc<97 & faminc>10

label define incomecat 1 "Less than $40k" 2 "$40k - $100k" 3 "Over $100k"
label values incomecat incomecat

gen ideo3=ideo5
recode ideo3 1/2=1 3=2 4/5=3 6=4
label define ideo3 1 "liberal" 2 "moderate" 3 "conservative"
label val ideo3 ideo3
label var ideo3 "Ideology 3 point"

recode pid3 4/5=3

gen age=2013-birthyr
gen agecat=1 if age<30
replace agecat=2 if age>29 & age<55
replace agecat=3 if age>54

label define agecat 1 "18-29" 2 "30-54" 3 "55+"
label values agecat agecat

recode q13_1-q14_10 (2=0)

svyset [pw=weight]

svy: mean q13_1-q13_7
tabstat q13_1-q13_7 [aw=weight], by(pid3) stat(mean n)
tabstat q13_1-q13_7 [aw=weight], by(gender) stat(mean n)
tabstat q13_1-q13_7 [aw=weight], by(region2) stat(mean n)


svy: mean q14_1-q14_10
tabstat q14_1-q14_10 [aw=weight], by(pid3) stat(mean n)
tabstat q14_1-q14_10 [aw=weight], by(gender) stat(mean n)
tabstat q14_1-q14_10 [aw=weight], by(region2) stat(mean n)


svy: tab q15, stubw(40)

svy: tab q12, stubw(40)

svy: tab q16, stubw(40)


